import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  // 主页  重定向到推荐页
  {
    path: '/',
    redirect: '/recommend',
    component: () => import('../views/Recommend.vue')
  },
  // 推荐页
  {
    path: '/recommend',
    name: 'Recommend',
    component: () => import('../views/Recommend.vue')
  },
  // 歌手页
  {
    path: '/singer',
    name: 'Singer',
    component: () => import(/* webpackChunkName: "about" */ '../views/Singer.vue')
  },
  // 排行榜页
  {
    path: '/rank',
    name: 'Rank',
    component: () => import(/* webpackChunkName: "about" */ '../views/Rank.vue')
  },
  // 个人页
  {
    path: '/mine',
    name: 'Mine',
    component: () => import(/* webpackChunkName: "about" */ '../views/Mine.vue')
  },
  // 搜索页
  {
    path: '/search',
    name: 'Search',
    component: () => import(/* webpackChunkName: "about" */ '../views/Search.vue')
  },
  // 歌手详情页面
  {
    path: '/singer/:id',
    name: 'SingerlistDetail',
    component: () => import('../components/detail/SingerlistDetail.vue')
  },
  // 歌单详情页面
  {
    path: '/songlist/:mid',
    name: 'SonglistDetail',
    component: () => import('../components/detail/SonglistDetail.vue')
  },
  // 专辑详情页面
  {
    path: '/album/:id',
    name: 'AlbunDetail',
    component: () => import('../components/detail/AlbumDetail.vue')
  },
  // 排行榜详情页
  {
    path: '/rank/:id',
    name: 'RanklistDetail',
    component: () => import('../components/detail/RankDetail.vue')
  },
  // 我的喜欢页面
  {
    path: '/mine/like',
    name: 'MineLike',
    component: () => import('../components/mine/MineLike.vue')
  },
  // 播放历史页面
  {
    path: '/mine/history',
    name: 'MineHistory',
    component: () => import('../components/mine/MineLike.vue')
  },
  // 喜欢歌手页面
  {
    path: '/mine/singer',
    name: 'MineSinger',
    component: () => import('../components/mine/MineSinger.vue')
  },
  // 喜欢榜单页面
  {
    path: '/mine/rank',
    name: 'MineRank',
    component: () => import('../components/mine/MineRank.vue')
  },
  // 喜欢歌单页面
  {
    path: '/mine/songlist',
    name: 'MineSongList',
    component: () => import('../components/mine/MineSongList.vue')
  },
  // 喜欢专辑页面
  {
    path: '/mine/album',
    name: 'MineAlbum',
    component: () => import('../components/mine/MineSongList.vue')
  },
  // MV播放界面
  {
    path: '/mv/:vid',
    name: 'MV',
    component: () => import('../components/base/MV.vue')
  }
]

const router = new VueRouter({
  routes
})

// router.beforeEach((to, from, next) => {
//   if (to.name !== 'Login') {
//     // next({ name: 'Recommend' })
//     next('/rank')
//     // next(console.log(to.name))
//   } else {
//     next(console.log('是'))
//   }
// })

const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push (location) {
  return originalPush.call(this, location).catch(err => err)
}

export default router
